package com.guigu.service.impl.design;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.guigu.mapper.design.DLevelSecondMapper;
import com.guigu.pojo.design.DLevelFirst;
import com.guigu.pojo.design.DLevelSecond;
import com.guigu.service.design.DLevelSecondService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author Mr.Zhang
 * @since 2024-12-17
 */
@Service
public class DLevelSecondServiceImpl extends ServiceImpl<DLevelSecondMapper, DLevelSecond> implements DLevelSecondService {

    @Autowired
    private DLevelSecondMapper dLevelSecondMapper;

    @Override
    public ArrayList<DLevelSecond> selectLevelSecondByFirstId(String firstId) {
        QueryWrapper<DLevelSecond> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("PARENT_ID", firstId);
        ArrayList<DLevelSecond> dLevelSeconds = (ArrayList<DLevelSecond>) dLevelSecondMapper.selectList(queryWrapper);
        return dLevelSeconds;
    }

    @Override
    public ArrayList<DLevelSecond> selectLevelSecond() {
        ArrayList<DLevelSecond> dLevelSeconds = (ArrayList<DLevelSecond>) dLevelSecondMapper.showDLevelSecond();
        System.out.println(dLevelSeconds);
        return dLevelSeconds;
    }

    @Override
    public Boolean insertSecond(DLevelSecond second) {
        int rows = dLevelSecondMapper.insert(second);
        return rows>0;
    }

    @Override
    public DLevelSecond selectDLevelSecondOrderByDescOne() {
        QueryWrapper<DLevelSecond> queryWrapper = new QueryWrapper<>();
        queryWrapper.orderByDesc("SECOND_ID");
        queryWrapper.last("limit 1");
        DLevelSecond dLevelSecond = dLevelSecondMapper.selectOne(queryWrapper);
        return dLevelSecond;

    }
}
